<?php


//no direct access
defined('_JEXEC') or die( 'Restricted access' );
//import the JController Class
jimport( 'joomla.application.component.model' );

class NvModelFlickr extends JModel {
	
	var $tesURL = "http://localhost/joomladev/pipe.rss";
	
	function getPicture($keyword ,$amt){
		
		$keyEncoded = urlencode($keyword);
		
		//set URL to yahoo pipe flickr module
		$URL = 'http://pipes.yahoo.com/pipes/pipe.run?_id=4vL_EcYT3hGbUTFp3rVd_w&_render=rss&amt='.$amt.'&keyword='.$keyEncoded;
		
		
				
		$options = array();
		
		
		$options['rssUrl'] = $URL;
		
		//parse rss object
		$parser =& JFactory::getXMLParser('rss',$options);
		
			
		//initiate data object array
		$data = array();
		$index = 0;
		//get link,title and image url and store it to an object array
		foreach ($parser->get_items(0,$amt) as $item){
					
			$flickr = new stdClass();
			$flickr->title = $item->get_title();
			$flickr->thumbnail = $item->get_enclosure()->get_thumbnail();
			
			$afterTrim = explode("_m",$item->get_enclosure()->get_link());
			
			$flickr->url = $afterTrim[0].$afterTrim[1];
			$flickr->link = $item->get_link();
			$data[$index++] = $flickr;
						 			
		}

		
		//return data array
		return $data;
		
	}
	

}
?>